package cn.serein.charging.user.controller;

import cn.serein.charging.common.pojo.JsonResult;
import cn.serein.charging.user.service.WxLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

@Slf4j
@RestController

public class WechatLoginController {

    @Autowired
    private WxLoginService wxLoginService;

    @GetMapping("/wx/login")
    public JsonResult wechatLogin(@PathParam("code") String code,
                                  @PathParam("nickName") String nickName){
        // 通过code调用微信的第三方接口获取用户的openId

        Integer userId = wxLoginService.login(code,nickName);
        // 通过工具类将code转为param

        return JsonResult.success(200, "success", userId);
    }
}
